<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy')?:array('jy'=>1);
$return['basic']=$this->plugin_setting('basic')?:array('jy'=>1);
$return['banner']=$return['basic']['image'];
if($_RQ['op']=='main'){
	//超时未支付订单取消
	$list=pdo_getall('jy_yuyue_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>'0'));
	if($list){
		$timeout=$return['basic']['timeout']?$return['basic']['timeout']:5;
		foreach($list as $row){
			if(time()-$row['createtime']>$timeout*60){
				pdo_update('jy_yuyue_order',array('status'=>3),array('id'=>$row['id']));
			}
		}
	}
	//查询所有未锁定、已审核的服务员工
	$worker_list=pdo_getall('jy_yuyue_worker',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>intval($_RQ['merchid']),'islock'=>'0','examine'=>'1'));
	if($worker_list){
		foreach($worker_list as &$item){
			$item['lev_name']=pdo_getcolumn('jy_yuyue_lev',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['lev']),'lev_name');
		    //已支付，已确认，已完成订单数
			$num1=pdo_count('jy_yuyue_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'0'));
			$num2=pdo_count('jy_yuyue_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'1'));
			$num3=pdo_count('jy_yuyue_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'2'));
			$num4=pdo_count('jy_yuyue_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'4'));
			$item['num']=$num1+$num2+$num3+$num4;
		}
	}
	$return['post']=array();
	$return['worker_list']=$worker_list;
	$sharelink='jy_yuyue/worker//fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
		'title'=>$return['pluginset']['share_title']?:'技师列表',
		'desc'=>$return['pluginset']['share_desc']?:'在线预约服务，一个属于自己的在线预约服务！',
		'link'=>custom_url($sharelink,true),
		'imgUrl'=>tomedia($return['pluginset']['share_image'])
	);
	exi($return);
}
if($_RQ['op']=='list'){
	exi($return);
}
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('没有找到该员工，请重新选择！','error','jy_yuyue/worker/main');
	}
	//查询该员工具体信息
	$worker=pdo_get('jy_yuyue_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//等级名称
	$lev_name=pdo_getcolumn('jy_yuyue_lev',array('uniacid'=>$_SESSION['uniacid'],'id'=>$worker['lev']),'lev_name');
	//可服务项目
	$service=explode(";",$worker['service']);
	$service=array_filter($service);
	foreach($service as $k=>&$item){
		$item=pdo_get('jy_yuyue_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item));	
		if(!$item['id']){
			unset($service[$k]);
		}else{
			$item['package']=json_decode($item['package'],true);
		}
	}
	//查询自己的项目
	$servicemy=pdo_getall('jy_yuyue_serve',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$worker['id'],'status'=>'1'));
	foreach($servicemy as $sm){
		$service[]=$sm;
	}
	$return['worker']=$worker;
	$return['service']=$service;
	$return['province']=file_get_contents('core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	//$return['data']=$data;
	$return['post']=array('timeid'=>'no','worker_id'=>$_RQ['id']);
	$this->session('worker_id',$_RQ['id']);
	exi($return);
}